package com.farmlei.zkt_c3100.lock;

import com.sun.jna.*;
import com.sun.jna.ptr.IntByReference;

/**
 * 虹软人脸识别SDK相关工具类
 */
public final class LockUtil {
    // 定义接口CLibrary，继承自com.sun.jna.Library
    public interface testdll extends Library {
        // msvcrt为dll名称,msvcrt目录的位置为:C:\Windows\System32下面,
        testdll Instance = (testdll) Native.loadLibrary((Platform.isWindows() ? "C:\\PullSDK\\x64\\plcommpro.dll" : "c"),
                testdll.class);
        // printf为msvcrt.dll中的一个方法.
        Pointer Connect(String format);

        Pointer ConnectExt(String format, IntByReference pErrorCode);

        void Disconnect(Pointer pointer);

        Pointer GetDeviceParam(Pointer pointer, byte[] buffer, IntByReference bufferSize, String items);

        Pointer GetDeviceData(Pointer pointer, byte[] buffer, IntByReference bufferSize, String tableName, String fieldNames, String filter, String options);

        Pointer GetRTLogExt(Pointer pointer, byte[] buffer, IntByReference bufferSize);

        Pointer ControlDevice(Pointer pointer, NativeLong operationID, NativeLong param1, NativeLong param2, NativeLong param3, NativeLong param4, String options);
    }

    public static void main(String[] args) throws Exception {
        // 调用printf打印信息
        IntByReference aa = new IntByReference();
        Pointer pointer = testdll.Instance.ConnectExt("protocol=TCP,ipaddress=192.168.1.201,port=4370,timeout=4000,passwd=", aa);
        System.out.println(pointer);
        System.out.println(aa.getValue());




        byte[] buffer = new byte[1024];
//        testdll.Instance.GetDeviceParam(pointer, buffer, new IntByReference(1024), "DeviceID,Door1SensorType,Door1Drivertime,Door1Intertime");
//
//        System.out.println(new String(buffer));
//        System.out.println(Arrays.toString(buffer));

        Pointer pointer1 = testdll.Instance.GetDeviceData(pointer, buffer, new IntByReference(1024), "transaction", "*", "EventType=27,EventType=0", "NewRecord");

        int length = 0;
        for (int i = 0; i < buffer.length; ++i) {
            if (buffer[i] == 0) {
                length = i;
                break;
            }
        }
        String records = new String(buffer, 0, length, "utf-8");
        System.out.println(records);


//        Pointer pointer1 = testdll.Instance.GetRTLogExt(pointer, buffer, new IntByReference(1024));
//        System.out.println(new String(buffer));
//        System.out.println(Arrays.toString(buffer));

//        Pointer pointer1 = testdll.Instance.ControlDevice(pointer, new NativeLong(1), new NativeLong(1), new NativeLong(1), new NativeLong(5), new NativeLong(0), "");
//        System.out.println(new String(buffer));
//        System.out.println(Arrays.toString(buffer));


        testdll.Instance.Disconnect(pointer);

    }

}
